package com.qk.mapper;

import com.qk.dto.UserDto;
import com.qk.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    @Insert("insert into user(username,password,name,phone,email,gender,status,dept_id,role_id,image,remark,create_time,update_time  ) " +
            "values(#{username},#{password},#{name},#{phone} ,#{email},#{gender},#{status},#{deptId},#{roleId},#{image},#{remark},#{createTime},#{updateTime}) ")
    void insert(User user);


    List<User> selectList(UserDto userDto);

    void delete(List<Integer> ids);

    void update(User user);

    //7. 根据角色查询用户
    @Select("select * from user ,role  where user.role_id = role.id and status =1 and  role.label = #{roleLabel} ")
    List<User> listByRole(String roleLabel);

    @Select("select user.*,role.label as role_label from user left join role on user.role_id = role.id where username = #{username}")
    User selectUserName(String username);
    @Select("SELECT id, username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time  FROM user WHERE id = #{id}")
    User selectById(Integer id);
    @Select("select * from user where status =1 and  dept_id = #{deptId} ")
    List<User> listByDept(Integer deptId);
}
